﻿using System;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data;
using Hangjing.DBUtility;
using Hangjing.Model;

namespace Hangjing.SQLServerDAL
{
    /// <summary>
    /// 物料单位管理
    /// </summary>
    public partial class Freeshifts
    {
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(FreeshiftsInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Freeshifts(");
            strSql.Append("title,starttime,endtime,workhours,salary,reveint1,reveint2,revevar1,revevar2,revefloat");
            strSql.Append(") values (");
            strSql.Append("@title,@starttime,@endtime,@workhours,@salary,@reveint1,@reveint2,@revevar1,@revevar2,@revefloat");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = 
			{
			    new SqlParameter("@title", SqlDbType.VarChar,256) ,            
                new SqlParameter("@starttime", SqlDbType.DateTime) ,            
                new SqlParameter("@endtime", SqlDbType.DateTime) ,            
                new SqlParameter("@workhours", SqlDbType.Int,4) ,            
                new SqlParameter("@salary", SqlDbType.Int,4) ,            
                new SqlParameter("@reveint1", SqlDbType.Int,4) ,            
                new SqlParameter("@reveint2", SqlDbType.Int,4) ,            
                new SqlParameter("@revevar1", SqlDbType.VarChar,256) ,            
                new SqlParameter("@revevar2", SqlDbType.VarChar,256) ,            
                new SqlParameter("@revefloat", SqlDbType.Decimal,5)             
              
            };

            parameters[0].Value = model.title;
            parameters[1].Value = model.starttime;
            parameters[2].Value = model.endtime;
            parameters[3].Value = model.workhours;
            parameters[4].Value = model.salary;
            parameters[5].Value = model.reveint1;
            parameters[6].Value = model.reveint2;
            parameters[7].Value = model.revevar1;
            parameters[8].Value = model.revevar2;
            parameters[9].Value = model.revefloat;
            return HJConvert.ToInt32(SQLHelper.ExecuteScalar(CommandType.Text, strSql.ToString(), parameters));
        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int Update(FreeshiftsInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Freeshifts set ");

            strSql.Append(" title = @title , ");
            strSql.Append(" starttime = @starttime , ");
            strSql.Append(" endtime = @endtime , ");
            strSql.Append(" workhours = @workhours , ");
            strSql.Append(" salary = @salary , ");
            strSql.Append(" reveint1 = @reveint1 , ");
            strSql.Append(" reveint2 = @reveint2 , ");
            strSql.Append(" revevar1 = @revevar1 , ");
            strSql.Append(" revevar2 = @revevar2 , ");
            strSql.Append(" revefloat = @revefloat  ");
            strSql.Append(" where id=@id ");

            SqlParameter[] parameters = 
			{
			    new SqlParameter("@id", SqlDbType.Int,4) ,            
                new SqlParameter("@title", SqlDbType.VarChar,256) ,            
                new SqlParameter("@starttime", SqlDbType.DateTime) ,            
                new SqlParameter("@endtime", SqlDbType.DateTime) ,            
                new SqlParameter("@workhours", SqlDbType.Int,4) ,            
                new SqlParameter("@salary", SqlDbType.Int,4) ,            
                new SqlParameter("@reveint1", SqlDbType.Int,4) ,            
                new SqlParameter("@reveint2", SqlDbType.Int,4) ,            
                new SqlParameter("@revevar1", SqlDbType.VarChar,256) ,            
                new SqlParameter("@revevar2", SqlDbType.VarChar,256) ,            
                new SqlParameter("@revefloat", SqlDbType.Decimal,5)             
              
            };

            parameters[0].Value = model.id;
            parameters[1].Value = model.title;
            parameters[2].Value = model.starttime;
            parameters[3].Value = model.endtime;
            parameters[4].Value = model.workhours;
            parameters[5].Value = model.salary;
            parameters[6].Value = model.reveint1;
            parameters[7].Value = model.reveint2;
            parameters[8].Value = model.revevar1;
            parameters[9].Value = model.revevar2;
            parameters[10].Value = model.revefloat;
            return SQLHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters);
        }

        /// <summary>
        /// 获取记录所有字段
        /// </summary>
        /// 此代码由杭景科技代码内部生成器自动生成
        /// <param>id</param>
        /// <returns>FreeshiftsInfo</returns>
        public FreeshiftsInfo GetModel(int id)
        {
            string sql = "select id,title,starttime,endtime,workhours,salary,reveint1,reveint2,revevar1,revevar2,revefloat from Freeshifts where  id = @id";
            SqlParameter parameter = new SqlParameter("@id", SqlDbType.Int, 4);
            parameter.Value = id;
            FreeshiftsInfo model = null;
            using (SqlDataReader dr = SQLHelper.ExecuteReader(CommandType.Text, sql, parameter))
            {
                if (dr.Read())
                {
                    model = new FreeshiftsInfo();
                    model.id = HJConvert.ToInt32(dr["id"]);
                    model.title = HJConvert.ToString(dr["title"]);
                    model.starttime = HJConvert.ToDateTime(dr["starttime"]);
                    model.endtime = HJConvert.ToDateTime(dr["endtime"]);
                    model.workhours = HJConvert.ToInt32(dr["workhours"]);
                    model.salary = HJConvert.ToInt32(dr["salary"]);
                    model.reveint1 = HJConvert.ToInt32(dr["reveint1"]);
                    model.reveint2 = HJConvert.ToInt32(dr["reveint2"]);
                    model.revevar1 = HJConvert.ToString(dr["revevar1"]);
                    model.revevar2 = HJConvert.ToString(dr["revevar2"]);
                    model.revefloat = HJConvert.ToDecimal(dr["revefloat"]);
                }
            }
            return model;
        }

        /// <summary>
        /// 获得总记录数
        /// </summary>
        /// 此代码由杭景科技代码内部生成器自动生成
        public int GetCount(string strWhere)
        {
            return (int)SQLHelper.ExecuteScalar(CommandType.StoredProcedure, "pagecount", new SqlParameter("@tblName", "Freeshifts"), new SqlParameter("@strWhere", strWhere));
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="pagesize">页尺寸</param>
        /// <param name="pageindex">页索引</param>
        /// <param name="strWhere">查询条件</param>
        /// <param name="orderName">排序字段</param>
        /// <param name="orderType">排序类型，1为降序，0为升序</param>
        /// <returns>图书列表</returns>
        ///此代码由杭景科技代码内部生成器自动生成
        public IList<FreeshiftsInfo> GetList(int pagesize, int pageindex, string strWhere, string orderName, int orderType)
        {
            IList<FreeshiftsInfo> infos = new List<FreeshiftsInfo>();
            SqlParameter[] parameters = 
			{
				new SqlParameter("@tblName", SqlDbType.VarChar,255),
				new SqlParameter("@strGetFields", SqlDbType.VarChar,1000),
				new SqlParameter("@primary", SqlDbType.VarChar,255),
				new SqlParameter("@orderName", SqlDbType.VarChar,255),
				new SqlParameter("@PageSize", SqlDbType.Int),
				new SqlParameter("@PageIndex", SqlDbType.Int),
				new SqlParameter("@OrderType", SqlDbType.Bit),
				new SqlParameter("@strWhere", SqlDbType.VarChar,1500)
			};
            parameters[0].Value = "Freeshifts";
            parameters[1].Value = "id,title,starttime,endtime,workhours,salary,reveint1,reveint2,revevar1,revevar2,revefloat";
            parameters[2].Value = "id";
            parameters[3].Value = orderName;
            parameters[4].Value = pagesize;
            parameters[5].Value = pageindex;
            parameters[6].Value = orderType;
            parameters[7].Value = strWhere;
            using (SqlDataReader dr = SQLHelper.ExecuteReader(CommandType.StoredProcedure, "pageselectpri", parameters))
            {
                while (dr.Read())
                {
                    FreeshiftsInfo info = new FreeshiftsInfo();
                    info.id = HJConvert.ToInt32(dr["id"]);
                    info.title = HJConvert.ToString(dr["title"]);
                    info.starttime = HJConvert.ToDateTime(dr["starttime"]);
                    info.endtime = HJConvert.ToDateTime(dr["endtime"]);
                    info.workhours = HJConvert.ToInt32(dr["workhours"]);
                    info.salary = HJConvert.ToInt32(dr["salary"]);
                    info.reveint1 = HJConvert.ToInt32(dr["reveint1"]);
                    info.reveint2 = HJConvert.ToInt32(dr["reveint2"]);
                    info.revevar1 = HJConvert.ToString(dr["revevar1"]);
                    info.revevar2 = HJConvert.ToString(dr["revevar2"]);
                    info.revefloat = HJConvert.ToDecimal(dr["revefloat"]);
                    infos.Add(info);
                }
            }
            return infos;
        }

        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <param name="Id"></param>
        /// 此代码由杭景科技代码内部生成器自动生成
        /// <returns></returns>
        public int Deldelivershifts(int Id)
        {
            StringBuilder str = new StringBuilder();
            str.Append("delete from Freeshifts where id=@id");
            SqlParameter[] Para = 
			{
				new SqlParameter("@id",SqlDbType.Int)
			};
            Para[0].Value = Id;

            return SQLHelper.ExecuteNonQuery(CommandType.Text, str.ToString(), Para);
        }


        /// <summary>
        /// 批量删除记录
        /// </summary>
        /// <param name="IdList"></param>
        /// <returns></returns>
        /// 此代码由杭景科技代码内部生成器自动生成
        public int DelList(string IdList)
        {
            StringBuilder str = new StringBuilder();
            str.Append("delete from Freeshifts where id in ({0})");

            return SQLHelper.ExecuteNonQuery(CommandType.Text, string.Format(str.ToString(), IdList), null);
        }




    }
}

